package it.unibz.easytravel.travel;

import java.io.File;
import java.io.IOException;

import org.apache.http.client.ClientProtocolException;

import it.unibz.easytravel.R;
import it.unibz.easytravel.serverconnection.ServerConnection;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class TravelSettingsActivity extends Activity {
	
		
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.application_settings_view);
		
		Button button_chooseTravel = (Button)findViewById(R.id.Button_ChooseTravel);
		button_chooseTravel.setOnClickListener(mChooseTravel);		
		
		Button button_disabletracking = (Button) findViewById(R.id.button_disabletracker);
		button_disabletracking.setOnClickListener(mStopTracker);
	
		Button button_enabletracking = (Button) findViewById(R.id.button_enabletracker);
		button_enabletracking.setOnClickListener(mStartTracker);
		
		Button button_synchronize = (Button) findViewById(R.id.Client);
		button_synchronize.setOnClickListener(mSynchronize);
		
		
	}
	
	private OnClickListener mChooseTravel = new OnClickListener()
	{
		public void onClick(View v)
		{
			Intent intent = new Intent(TravelSettingsActivity.this, EditTravel.class);
            startActivity(intent);
		}
	};
	
	private OnClickListener mStopTracker = new OnClickListener() {
		public void onClick(View v) {
		    stopService(new Intent(new Intent("it.unibz.easytravel.tracker.REMOTE_SERVICE")));
	
		}
	};
	
	private OnClickListener mStartTracker = new OnClickListener() {
		public void onClick(View v) {			
			startService(new Intent(new Intent("it.unibz.easytravel.tracker.REMOTE_SERVICE")));  
					
		}
		 
	};
	
	private OnClickListener mSynchronize = new OnClickListener() {
		public void onClick(View v) {
			try {
				ServerConnection.sendZip(new File("data/data/it.unibz.easytravel/files/test.zip"));
			} catch (ClientProtocolException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	};
}
